package com.itwn.springcloud.controller;

import com.itwn.springcloud.entityes.CommonResult;
import com.itwn.springcloud.entityes.Payment;
import com.itwn.springcloud.service.PaymentFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class OrderFeignController {

    @Resource
    private PaymentFeignService paymentFeignService;

    @GetMapping("/consumer/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){

        return paymentFeignService.getPaymentById(id);
    }

    /**
     * 模拟报错
     *      openfeign-ribbon ,客户端请求等待响应时间一般默认等待一秒,但是生产者设置了3秒
     *
     *      There was an unexpected error (type=Internal Server Error, status=500).
     *      Read timed out executing GET http://CLOUD-PAYMENT-SERVICE/payment/feign/timeout
     * @return
     */
    @GetMapping("/consumer/payment/feign/timeout")
    public String paymentFeignTimeout(){
        return paymentFeignService.paymentFeignTimeout();
    }

}
